package com.xxwu.review.mybatis.controller;

import com.xxwu.review.mybatis.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MybatisController {
    //以下是通过注解方式实现增删改查
    @Select("select * from userinfo where id = #{userId}")
    UserInfo selectByPrimaryKey(@Param("userId") int id);

    @Options(useGeneratedKeys = true , keyProperty = "id")
    @Insert("insert into userinfo(username, password, age, gender, phone) " +
            "values(#{user.username}, #{user.password}, " +
            "#{user.age}, #{user.gender}, #{user.phone})")
    Integer insert(@Param("user") UserInfo userInfo);

    @Update("update userinfo set username = #{username} where id = #{id}")
    Integer updateByPrimaryKey(String username, Integer id);

    //通过XML方式
    List<UserInfo> selectByPrimaryKeyXML();

    Integer updateByPrimaryKeyXML(String username, Integer id);
}
